from django.contrib import admin
from .models import Order,Shop,Good,Good_of_Order
# Register your models here.

class GoodInline(admin.TabularInline):
    model = Good_of_Order
    extra = 2


class GoodAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['good_name']}),
        (None, {'fields': ['good_price']}),
        (None, {'fields': ['good_code']}),
        (None, {'fields': ['good_type']}),
    ]
    list_display = ('good_name', 'good_price', 'good_code', 'good_type')
admin.site.register(Good, GoodAdmin)

class OrderAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['order_code']}),
        (None, {'fields': ['shop']}),
        ('详细时间', {'fields': ['created_date'], 'classes': ['collapse']}),
    ]
    inlines = [GoodInline]
    list_display = ('order_code', 'shop','created_date', 'was_created_recently')
    list_filter = ['created_date','shop']
    search_fields = ['order_code']
admin.site.register(Order, OrderAdmin)

class ShopAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['shop_name']}),
    ]
admin.site.register(Shop, ShopAdmin)